#!/bin/bash

usermod --groups sudo www-data
usermod --shell /bin/bash www-data
usermod --groups sudo,dialout opsadmin1

mkdir -p /opt/osdp-conformance/run/ACU
mkdir -p /opt/osdp-conformance/run/MON
mkdir -p /opt/osdp-conformance/run/PD
mkdir -p /opt/osdp-conformance/results
mkdir -p /opt/osdp-conformance/log

# set up default parameter files 

echo "NOTICE: OSDP parameters may be updated."

cp /opt/osdp-conformance/run/ACU/open-osdp-params-ACU.json /opt/osdp-conformance/run/ACU/open-osdp-params.json
cp /opt/osdp-conformance/run/PD/open-osdp-params-PD.json /opt/osdp-conformance/run/PD/open-osdp-params.json
cp /opt/osdp-conformance/run/MON/open-osdp-params-MON.json /opt/osdp-conformance/run/MON/open-osdp-params.json

# resave settings
cd /tmp
rm -f stderr stdout
/opt/tester/cgi-bin/save-osdp-conformance >stdout 2>stderr

ln -s /opt/osdp-conformance/www/index-conformance.html /opt/osdp-conformance/www/index.html
cp /opt/osdp-conformance/etc/osdp.conf /etc/apache2/sites-enabled
rm -f /etc/apache2/sites-enabled/000*

rm -f /tmp/stderr
ln 2>/tmp/stderr -s /etc/apache2/mods-available/cgi.load /etc/apache2/mods-enabled/cgi.load
ln 2>/tmp/stderr -s /etc/apache2/mods-available/cgid.load /etc/apache2/mods-enabled/cgid.load
ln 2>/tmp/stderr -s /etc/apache2/mods-available/cgid.conf /etc/apache2/mods-enabled/cgid.conf
/etc/init.d/apache2 stop
/etc/init.d/apache2 start

echo web server configuration updated.

cp /opt/osdp-conformance/etc/www-data /etc/sudoers.d
chown root /etc/sudoers.d/www-data

echo >>/opt/osdp-conformance/log/install.log libosdp-conformance was installed.

